package com.hh.game.service.gateway.filter.statistics;

import com.hh.game.common.base.cache.redis.RedisResource;
import org.redisson.api.RList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

public class RedisStatisticsManager implements StatisticsManager {
    private RedisResource redisResource;
    private String applicationName;

    private final static String STATISTICS_KEY = "statistics-qps-";

    public RedisStatisticsManager(RedisResource redisResource, String applicationName) {
        this.redisResource = redisResource;
        this.applicationName = applicationName;
    }

    @Override
    public void save(StatisticsInfo info) {
        RList<StatisticsInfo> list = redisResource.getList(STATISTICS_KEY + applicationName);
        list.add(info);
        if(list.size() > (60/5) * 24 * 7){ //7天
            list.remove(0);
        }
    }
}
